/**
 *
 */
package com.zhuoyue.elmt.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.eit.eitsite.common.config.Global;
import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.web.BaseController;
import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.elmt.entity.WbMtGroupStaff;
import com.zhuoyue.elmt.service.WbMtGroupStaffService;

/**
 * 小组和人员的关联Controller
 * @author JiangYH
 * @version 2017-02-08
 */
@Controller
@RequestMapping(value = "${adminPath}/elmt/wbMtGroupStaff")
public class WbMtGroupStaffController extends BaseController {

	@Autowired
	private WbMtGroupStaffService wbMtGroupStaffService;
	
	@ModelAttribute
	public WbMtGroupStaff get(@RequestParam(required=false) String id) {
		WbMtGroupStaff entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = wbMtGroupStaffService.get(id);
		}
		if (entity == null){
			entity = new WbMtGroupStaff();
		}
		return entity;
	}
	
	@RequiresPermissions("elmt:wbMtGroupStaff:view")
	@RequestMapping(value = {"list", ""})
	public String list(WbMtGroupStaff wbMtGroupStaff, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<WbMtGroupStaff> page = wbMtGroupStaffService.findPage(new Page<WbMtGroupStaff>(request, response), wbMtGroupStaff); 
		model.addAttribute("page", page);
		return "zhuoyue/elmt/wbMtGroupStaffList";
	}

	@RequiresPermissions("elmt:wbMtGroupStaff:view")
	@RequestMapping(value = "form")
	public String form(WbMtGroupStaff wbMtGroupStaff, Model model) {
		model.addAttribute("wbMtGroupStaff", wbMtGroupStaff);
		return "zhuoyue/elmt/wbMtGroupStaffForm";
	}

	@RequiresPermissions("elmt:wbMtGroupStaff:edit")
	@RequestMapping(value = "save")
	public String save(WbMtGroupStaff wbMtGroupStaff, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, wbMtGroupStaff)){
			return form(wbMtGroupStaff, model);
		}
		wbMtGroupStaffService.save(wbMtGroupStaff);
		addMessage(redirectAttributes, "保存小组和人员的关联成功");
		return "redirect:"+Global.getAdminPath()+"/elmt/wbMtGroupStaff/?repage";
	}
	
	@RequiresPermissions("elmt:wbMtGroupStaff:edit")
	@RequestMapping(value = "delete")
	public String delete(WbMtGroupStaff wbMtGroupStaff, RedirectAttributes redirectAttributes) {
		wbMtGroupStaffService.delete(wbMtGroupStaff);
		addMessage(redirectAttributes, "删除小组和人员的关联成功");
		return "redirect:"+Global.getAdminPath()+"/elmt/wbMtGroupStaff/?repage";
	}

}